<?php

namespace app\common\model;

use think\Model;


class Report extends Model
{


    // 表名
    protected $name = 'report';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;
    // 追加属性
    protected $append = [
        'status_text',
        'service_type_text',
    ];

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4')];
    }
    public function getServiceTypeList()
    {
        return ['0' => __('Service_type 0'), '1' => __('Service_type 1'), '2' => __('Service_type 2')];
    }
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getServiceTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['service_type']) ? $data['service_type'] : '');
        $list = $this->getServiceTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function warranty()
    {
        return $this->belongsTo('\app\common\model\work\Warranty', 'warranty_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
